package com.ruoyi.web.controller.union;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.union.domain.Article;
import com.ruoyi.union.service.IArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/union/article")
public class ArticleController extends BaseController {

    @Resource
    private IArticleService articleService;

    @GetMapping("/list")
    public TableDataInfo list(Article query) {
        startPage();
        List<Article> list = articleService.selectArticleList(query);
        return getDataTable(list);
    }

    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(articleService.selectArticleById(id));
    }

    @PostMapping
    public AjaxResult add(@RequestBody Article body) {
        return toAjax(articleService.insertArticle(body));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody Article body) {
        return toAjax(articleService.updateArticle(body));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(articleService.deleteArticleByIds(ids));
    }
}


